package com.example.viewpageapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

import java.util.ArrayList;

public class SpinnerDialogMainActivity extends AppCompatActivity {

    private Spinner spinner1;
    private String[] sp_item = {",火星","非洲","欧洲","南极","北美"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_spinner_dialog_main);
        spinner1 = findViewById(R.id.sp_item);

        //适配器加载
        ArrayAdapter<String> startAdapter = new ArrayAdapter<>(this,R.layout.sp_item,sp_item);
        spinner1.setAdapter(startAdapter);
        spinner1.setPrompt("请输入合适的地区");



        spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(SpinnerDialogMainActivity.this,"选择成功",Toast.LENGTH_SHORT).show();
            }
            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });




    }
}